﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class SimilarTextWebCrawlerWCFService : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void submitButton_Click(object sender, EventArgs e)
    {
        if (!(similarWordTextBox.Text.Length > 0) ||
            !(urlTextBox.Text.Length > 0) ||
            !(depthTextBox.Text.Length > 0))
        {
            this.output.InnerHtml = "<font color=\"red\"><b>INCORRECT INPUT.</b></font>";
            return;
        }
        SimilarTextWebCrawler.SimilarTextWebCrawlerWCFServiceClient client =
            new SimilarTextWebCrawler.SimilarTextWebCrawlerWCFServiceClient();
        string[] similarStuff = null;
        try
        {
            similarStuff = client.GetSimilarWords(
                new Uri(urlTextBox.Text),
                similarWordTextBox.Text,
                Convert.ToInt32(depthTextBox.Text));
            client.Close();
        }
        catch (Exception ex)
        {
            this.output.InnerText = ex.ToString();
        }
        if (similarStuff != null && similarStuff.Length != 0)
        {
            string words = "";
            foreach (string word in similarStuff)
            {
                words += word;
                words += ", ";
            }
            this.output.InnerText = "Output: " + words;
        }
    }
}